<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class JR_Module
{
	function __get($property_name)
	{
		if($property_name=='load')
		{
			$ci = & get_instance();
			if(!isset($ci->module_load))
			{
				$ci->module_load = clone $ci->load;
				$ci->module_load->remove_package_path();
				$ci->module_load->work_space = "module"; 
			}
			return $ci->module_load; 
		}
		else
		{
			$ci = &get_instance();
			$this->$property_name = $ci->$property_name;
		}
		return $this->$property_name;
	}

	function __call($name,$arguments)
	{
		$CI = &get_instance();
		return call_user_func_array(array($CI,$name), $arguments) ;   
	}

	
	function __construct()
	{
		$class_name = get_class($this);
		// echo $class_name;exit;
		
		$class_segs = explode('_',$class_name);
		array_pop($class_segs);
		//echo $module_folder_name;exit; 
		$module_folder_name = 
			isset($this->module_folder_name)
			?$this->module_folder_name
			:implode('_',$class_segs);
		// echo $module_folder_name;exit; 
		$module_folder_path = APPPATH."modules/".$module_folder_name;
		//echo $module_folder_path;exit ; 
		$this->load->remove_package_path(); 
		$this->load->add_package_path($module_folder_path); 
	} 
}

class Module_Library
{
	function __get($property_name)
	{
		if(!isset($this->$property_name))
		{
			$ci = & get_instance();
			if($property_name == "load")
			{
				$this->load = $ci->module_load;
			}
			else
			{
				$this->$property_name = $ci->$property_name;
			}
		}
		return $this->$property_name ; 
	}
}